//
//  YZResetPasswordVC.m
//  VET
//
//  Created by 刘文靖 on 2018/7/5.
//  Copyright © 2018年 YZ. All rights reserved.
//

#import "YZResetPasswordVC.h"
#import "YZGradientBtn.h"
#import "YZPersonalVM.h"
#import "YZUser.h"
@interface YZResetPasswordVC ()
@property (weak, nonatomic) IBOutlet UITextField *pwdTF;
@property (weak, nonatomic) IBOutlet YZGradientBtn *confirmButton;
@property (strong, nonatomic) YZPersonalVM *viewModel;

@end

@implementation YZResetPasswordVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"设置登录密码";
    RACSignal *verCodeSignal = [self.pwdTF.rac_textSignal map:^id(NSString *str) {
        return @(str.length >= 6 && str.length <= 16);
    }];
    RAC(self.confirmButton, enabled) = verCodeSignal;
}

- (IBAction)confirmButtonClicked {
    [[self.viewModel modifyPassword:self.pwdTF.text mobile:self.mobile?:[YZUser sharedInstance].phone verCode:self.verCode] subscribeNext:^(id  _Nullable x) {
        ;
    } completed:^{
        [self.navigationController popToRootViewControllerAnimated:YES];
    }];
}

- (YZPersonalVM *)viewModel{
    if (!_viewModel) {
        _viewModel = [[YZPersonalVM alloc] init];
    }
    return _viewModel;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [super touchesBegan:touches withEvent:event];
    [self.view endEditing:YES];
}
@end
